RESTful Engine API Tutorial: Constructing Simple Request Bodies Using Base64 Encoded Data
Now that you have sent your first template for processing and retrieved the completed document, we will step through putting together a request body with another template and data source so you can feel more comfortable doing this for your own templates and data sources later. In this tutorial, we will use base64 encoded data to post our template.
Just for your reference, here is a template version of the JSON request body we will be using:
{
"OutputFormat": "string",
"Data": "string", //When using Base64 encoded data, we will populate the "Data" entry with the base64 string
"Datasources":
[
{
"Name": "string",
"Type": "string",
"Data": "string" //When using Base64 encoded data, we will populate the "Data" entry with the base64 string
}
],
"TrackImports": false,
"TrackErrors": 3
}
You can also download the template request body as a file here: templatedRequestBody.json
Clicking on the link above will open the file in your browser. Make sure to save the file to your machine (CTRL+S).
Note that the templated request body above does not contain all possible values and configurations that our engine offers, but the basic values you will need to run a simple template with one data sourc
For this tutorial, we will be using the following template and data source (download these files):
Clicking on the link above will open the file in your browser. Make sure to save the file to your machine (CTRL+S).
Request Body Using Base64 Encoded Data
Download the provided "templatedRequestBody.json" and open it in a text editor
- Any text editor will work but in the long term we recommend using Visual Studio Code as it is a lightweight editor that will help with the formatting of the JSON in the request body
We will now begin replacing the "string" placeholders in the request body with the values we want:
First we will set the output format. The RESTful engine supports a handful file formats that you can choose to output in. For this tutorial we will use PDF. So in the request body set the
"OutputFormat"
value to"pdf"
. For a full list of output formats, check out the example request body here.Next we have the "Data" entry. Here we will pass in our template data as a base64 encoded string. To do so we will use the following online encoder
- When you open the online encoder, under "Option 2" click "Choose File" button and select the template file you downloaded earlier, then click encode.
- Then copy the entire base64 string and paste it as the value of the "Data" entry. Make sure to encompass the base64 string in quotations (represent it as a string) These strings can be long so make sure you get every character in the string when copying
- Note that you can use any base64 encoder you want
For this part of the tutorial we will set
"ConnectionString"
asnull
. The reason for this is that we will be providing the template via a base64 encoded string. For our RESTful engine, you either pass the data in as a connection string, or as a base64 encoded string (as we are in this part of the tutorial). So since we will be populating the"Data"
entry, we will set the"ConnectionString"
entry tonull
.
Now we will set our "Datasources", which is a list of data sources your template needs. So if you have multiple data sources used in your template you will have multiple entries under the "Datasources" entry. For this tutorial, however, our template only requires one data source, so we will only have one entry.
For
"Name"
, we will enter"MANF_DATA_2009"
noteThe data source name is specified during the creation of the template. So when you create your own template and connect a data source to it, you will specify the name then and use that name here when construction your request body.
We offer a handful of data source types that we support for our RESTful engine, for this tutorial we are using an XML data source. So set
"Type"
to"xml"
.Similar to template data, since we are using the
"Data"
entry with the data source data passed as a base64 encoded string, we will set the"ConnectionString"
entry to null.Next we have the "Data" entry. Here we will pass in our datasource data as a base64 encoded string. To do so we will use the following online encoder
- When you open the online encoder, under "Option 2" click "Choose File" button and select the template file you downloaded earlier, then click encode.
- Then copy the entire base64 string and paste it as the value of the "Data" entry. Make sure to encompass the base64 string in quotations (represent it as a string) These strings can be long so make sure you get every character in the string when copying
- Note that you can use any base64 encoder you want
You have now completed constructing the request body for this template using connection strings. You can test it in SwaggerHub by following the steps for posting and retrieving documents in the previous tutorial. However, instead of executing the provided sample request body provided in SwaggerHub, we will replace it with the body we just created:
- Go through the same steps as in the previous tutorial for using the RESTful engine on SwaggerHub.
- When you get to "step 4" in the tutorial, click "Try it out", then paste your request body in:
Now you can follow the rest of the steps in the other tutorial to check the status of the document, and then get the document once it is complete.
Next Steps
Now that you have constructed your own RESTful request body using connection strings, and were able to successfully post it and later on retrieve the processed document, consider constructing a request body using base64 data, or setting up your own RESTful engine to do some more of your own testing. If this is something you wish to do, here are some relevant links:
- RESTful Engine API Tutorial: Constructing Simple Request Bodies Using Connection Strings
- Fluent RESTful SwaggerHub Documentation
If you are ready to setup your own RESTful engine, check out how to setup your own RESTful engine here: